﻿using System.ComponentModel.DataAnnotations;
using System.Web;

namespace AddressBookDev.ViewModels
{
    public class ContactViewModel
    {
        public int Id { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "Must be at least {2} and less than {1} characters long.", MinimumLength = 3)]
        [Display(Name = "Contact Name")]
        public string Name { get; set; }

        [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                            @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                            @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$",
                            ErrorMessage = "Email is not valid")]
        [StringLength(256, ErrorMessage = "The {0} must be less than {1} characters long.")]
        [Display(Name = "Email")]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }

        [StringLength(50, ErrorMessage = "The {0} must be less than {1} characters long.")]
        [Display(Name = "Phone Number")]
        [DataType(DataType.PhoneNumber)]
        public string Phone { get; set; }

        [StringLength(512, ErrorMessage = "The {0} must be less than {1} characters long.")]
        [Display(Name = "Address")]
        public string Address { get; set; }

        private string _picture;

        public string Picture
        {
            get
            {
                if (string.IsNullOrEmpty(_picture))
                {
                    return Utilities.Images.CreateImageUrl("Contact.jpg");
                }
                return _picture;
            }
            set { _picture = value; }
        }

        public int UserId { get; set; }

        [Display(Name = "PictureFile")]
        public HttpPostedFileBase PictureFile { get; set; }

        public string ServerPath { get; set; }
        private int _picWidth;

        public int PicWidth
        {
            get { return _picWidth; }
            set
            {
                if (value <= 0)
                {
                    _picWidth = 240;
                }
                else
                {
                    _picWidth = value;
                }
            }
        }
        private int _picHeight;
        public int PicHeight
        {
            get { return _picHeight; }
            set
            {
                if (value <= 0)
                {
                    _picHeight = 240;
                }
                else
                {
                    _picHeight = value;
                }
            }
        }
        public int PicX { get; set; }
        public int PicY { get; set; }
    }
}